﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelSoft.HotelManagement_BUS;
using System.Collections;
using HotelSoft.HotelManagement_DTO;

namespace HotelSoft.HotelManagement_GUI
{
    public partial class frmCapnhat_THONGTINKHACHSAN : Form
    {
        // Define the CS_DROPSHADOW constant
        private const int CS_DROPSHADOW = 0x00020000;

        // Override the CreateParams property
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }
        Double temp = 1;
        TT_KhachSanDTO dtoKS;
        TT_KhachSanBUS busKS = new TT_KhachSanBUS();
        public bool bNhapDung = false;

        public frmCapnhat_THONGTINKHACHSAN()
        {
            InitializeComponent();
        }

        private void frmCapnhat_THONGTINKHACHSAN_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            getInfoKS();
            DieukienMo(false);
        }

        public void DieukienMo(bool Mo)
        {
            txtEmail.ReadOnly = !Mo;
            txtWebsite.ReadOnly = !Mo;
            txtSoDT.ReadOnly = !Mo;
            txtDiachi.ReadOnly = !Mo;
            Gru_LKL.Enabled = Mo;
            Gru_TXS.Enabled = !Mo;
        }

        private void getInfoKS()
        {
            DataTable tbl = new DataTable();
            busKS = new TT_KhachSanBUS();
            tbl = busKS.SelectAll();
            lblTenKS.Text = tbl.Rows[0].ItemArray[0].ToString();
            txtDiachi.Text = tbl.Rows[0].ItemArray[1].ToString();
            txtSoDT.Text = tbl.Rows[0].ItemArray[2].ToString();
            txtEmail.Text = tbl.Rows[0].ItemArray[3].ToString();
            txtWebsite.Text = tbl.Rows[0].ItemArray[4].ToString();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Opacity = this.Opacity + 0.1;
            if (this.Opacity == temp)
            {
                timer1.Enabled = false;
            }
        }

        private void Btn_Thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Btn_Sua_Click(object sender, EventArgs e)
        {
            if (lblTenKS.Text != "")
                DieukienMo(true);
            else
            {
                MessageBox.Show("Hãy bấm nút: nạp thông tin để lấy thông tin");
                btnLoad.Focus();
            }
        }

        private void Btn_Load_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Btn_Luu_Click(object sender, EventArgs e)
        {
            try
            {
                dtoKS = new TT_KhachSanDTO();
                dtoKS.WEBSITE = txtWebsite.Text;
                dtoKS.EMAIL = txtEmail.Text;
                dtoKS.SDTKS = txtSoDT.Text;
                dtoKS.DIACHIKS = txtDiachi.Text;
                dtoKS.TENKS = lblTenKS.Text;

                if(!busKS.Update(dtoKS))
                {
                    MessageBox.Show("Thất bại! Xin hãy kiểm tra lại");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Xin hãy nhập đầy đủ thông tin");
            }
            DieukienMo(false);
            btnThoat.Focus();
        }

        private void Btn_Khongluu_Click(object sender, EventArgs e)
        {
            DieukienMo(false);
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            getInfoKS();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
